//
//  NBSearchBar.swift
//  NBSinaWeibo
//
//  Created by ac on 16/5/19.
//  Copyright © 2016年 ac. All rights reserved.
//

import UIKit

class NBSearchBar: UIView {
    
    @IBOutlet weak var cancelBtn: UIButton!
    @IBOutlet weak var rightConstraint: NSLayoutConstraint!
    @IBAction func cancelBtnClick(sender: UIButton) {
        rightConstraint.constant = 0
        UIView.animateWithDuration(0.25) { 
            self.layoutIfNeeded()
        }
        self.endEditing(true)
    }
    @IBAction func searchTxtChanged(sender: UITextField) {
        rightConstraint.constant = cancelBtn.bounds.width
        UIView.animateWithDuration(0.25) {
            self.layoutIfNeeded()
        }
    }
    @IBOutlet weak var searchTxt: UITextField!
    class func loadXibView() -> NBSearchBar {
        let xibView = NSBundle.mainBundle().loadNibNamed("NBSearchBar", owner: nil, options: nil).last as! NBSearchBar
        return xibView
    }
    
    override func awakeFromNib() {
        
        
        self.bounds.size.width = ScreenWidth
        searchTxt.leftView = UIImageView(image: UIImage(named: "searchbar_textfield_search_icon"))
        searchTxt.leftViewMode = .Always
        searchTxt.leftView?.frame = CGRect(x: 0, y: 0, width: 50, height: 40)
        searchTxt.leftView?.contentMode = .Center
        
//        searchTxt.layer.cornerRadius = 20
//        searchTxt.layer.masksToBounds = true
//        searchTxt.layer.borderWidth = 2
//        searchTxt.layer.borderColor = UIColor.orangeColor().CGColor
        
        
    }
    
    
}
